<template>
  <div>
    <h2>购物车</h2>
    <div v-for="item in cartItems" :key="item.id">
      {{ item.name }} - ¥{{ item.price }} - 数量：{{ item.quantity }}
      <button @click="increment(item)">+</button>
      <button @click="decrement(item)">-</button>
    </div>
    <p>总价：¥{{ total }}</p>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex';

export default {
  computed: {
    ...mapState(['cartItems', 'total'])
  },
  methods: {
    ...mapMutations(['increment', 'decrement'])
  }
};
</script>